package com.bole.controller;


import com.bole.data.Result;
import com.bole.data.ResultEnum;
import com.bole.dto.car.Page;
import com.bole.feign.reception.EsFeign;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("search")
public class SearchController {

    @Autowired
    private EsFeign esFeign;

    @RequestMapping("toSearch")
    public String toSearch(String searchName, Model model) {
        model.addAttribute("searchName", searchName);
        return "list";
    }


    @GetMapping("searchInfo")
    @ResponseBody
    @ApiOperation(value = "查询车辆信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "searchName", value = "searchName", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(name = "pageNum", value = "pageNum", required = true, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "pageSize", required = true, dataTypeClass = Integer.class),
    })

    public Result listSearchByName(@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, String searchName) {
        Page searchPage = esFeign.listSearchByName(pageNum, pageSize, searchName);
        // System.out.println(searchPage.getTotalPage());
        return Result.response(ResultEnum.OK).setData(searchPage);
    }


    @PostMapping("selectCarSeriesId")
    @ResponseBody
    @ApiOperation(value = "根据车系查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "pageNum", required = true, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "pageSize", required = true, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "carSeriesId", value = "carSeriesId", required = true, dataTypeClass = Long.class),
            @ApiImplicitParam(name = "detailsId", value = "detailsId", required = true, dataTypeClass = String.class)
    })

    public Result selectCarSeriesId(@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                    @RequestParam("carSeriesId") Long carSeriesId,
                                    @RequestParam("detailsId") String detailsId) {
        Page searchPage = esFeign.selectCarSeriesId(pageNum, pageSize, carSeriesId,detailsId);
        // System.out.println(searchPage.getTotalPage());
        return Result.response(ResultEnum.OK).setData(searchPage);
    }

}
